package com.jk.bgmainprovider.service;

import com.jk.bgmainprovider.dao.AdmDao;
import com.jk.bgmainprovider.entity.AdmEntity;
import com.jk.bgmainprovider.entity.AdminMoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @描述
 * @参数 $
 * @返回值 $
 * @创建人 lgf
 * @创建时间 $
 * @修改人和其它信息
 */
@Service
public class AdmService {
    @Resource
    private AdmDao admDao;
    @Autowired
    private MongoTemplate mongoTemplate;

    public Map login(AdmEntity adm) {
        HashMap map = new HashMap();
        AdmEntity user=  admDao.findNum(adm.getAdmNum());
            if (user!=null){
                if (adm.getAdmPwd().equals(user.getAdmPwd())){
                    AdminMoEntity ad = new AdminMoEntity();
                    ad.setWardenId(user.getAdmId());
                    ad.setWardenNum(user.getAdmNum());
                    ad.setWardenOperate(user.getAdmName()+"登录");
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    ad.setWardenDate(sdf.format(new Date()));
                    mongoTemplate.save(ad);
                    map.put("code",200);
                }else {
                    map.put("code",201);
                }
            }else {
                map.put("code",202);
            }
        return  map;
    }
}
